package com.newsmanagement.service;


import com.newsmanagement.mapper.UserMapper;
import com.newsmanagement.model.User;
import com.newsmanagement.model.UserExample;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by xiaopeng on 2017/8/1.
 */

@Service
public class UserService {

     @Autowired
     UserMapper userMapper;


     public UserExample getUserExample(User user){
          UserExample example=new UserExample();
          UserExample.Criteria criteria=example.createCriteria();
          if(StringUtils.isNotBlank(user.getOpenid())){
               criteria.andOpenidEqualTo(user.getOpenid());
          }
          if (user.getParentId()!=null && user.getParentId()>0){
               criteria.andParentIdEqualTo(user.getParentId());
          }
          if(user.getProxyId() !=null && user.getProxyId()>0){
               criteria.andProxyIdEqualTo(user.getProxyId());
          }
          example.setOrderByClause("id DESC");
          return  example;
     }

     public User getUserInfo(){
         return userMapper.selectByPrimaryKey();
     }

}
